package day230410;

import java.util.Scanner;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/4/11 18:44
 * 两个字符串的最长公共子串
 */
public class Main02 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String st1 = scan.nextLine();
        String st2 = scan.nextLine();
        String res;
        if (st1.length() > st2.length()) {
            res = getLongestSubString(st1, st2);
        } else {
            res = getLongestSubString(st2, st1);
        }
        System.out.println(res);
        scan.close();
    }

    private static String getLongestSubString(String str1, String str2) {
        char[] ch1 = str1.toCharArray();
        char[] ch2 = str2.toCharArray();
        int len1 = ch1.length;
        int len2 = ch2.length;
        int start = 0; // 记录最长子串起始位置
        int maxLen = 0; // 记录最大长度
        // dp[1][1] 表示str1第一个字符结尾和str2第一个字符结尾的公共子串的最大
        // if i == j dp[i][j] = dp[i-1][j-1]+1
        int[][] dp = new int[len1 + 1][len2 + 1];
        for (int i = 1; i <= len1; i++) {
            for (int j = 1; j <= len2; j++) {
                if (ch1[i-1] == ch2[j-1]) {
                    // 相同, 字符串长度累加
                    dp[i][j] = dp[i-1][j-1] + 1;
                    if (dp[i][j] > maxLen) {
                        maxLen = dp[i][j];
                        start = i - maxLen;
                    }
                }
            }
        }
        return str1.substring(start, start + maxLen);
    }
}
